import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:ui_demo/talker/talker_page.dart';

import 'local_storage/sp_test.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return Container(
      child: Row(
        children: [
          Column(
            children: [
              Padding(
                padding: const EdgeInsets.all(8.0),
                child: Center(
                  child: MaterialApp(
                    title: 'Flutter Demo',
                    theme: ThemeData(
                      colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
                      useMaterial3: true,
                    ),
                    home: TalkerPage(),
                  ),
                ),
              ),
            ],
          ),
        ],
      ),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      // This call to setState tells the Flutter framework that something has
      // changed in this State, which causes it to rerun the build method below
      // so that the display can reflect the updated values. If we changed
      // _counter without calling setState(), then the build method would not be
      // called again, and so nothing would appear to happen.
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    // This method is rerun every time setState is called, for instance as done
    // by the _incrementCounter method above.
    //
    // The Flutter framework has been optimized to make rerunning build methods
    // fast, so that you can just rebuild anything that needs updating rather
    // than having to individually change instances of widgets.
    return Scaffold(
      appBar: AppBar(
        // TRY THIS: Try changing the color here to a specific color (to
        // Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
        // change color while the other colors stay the same.
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        // Here we take the value from the MyHomePage object that was created by
        // the App.build method, and use it to set our appbar title.
        title: Text(widget.title),
      ),
      body: Listener(
          onPointerSignal: (event) {
            if (event is PointerScrollEvent) {
              print("event :${event.scrollDelta}");
            }
          },
          child: Center(
              child: Row(
            mainAxisSize: MainAxisSize.min,
            children: [
              _createButtonText(context),
              const Padding(
                padding: EdgeInsets.all(20),
                child: SizedBox(
                  height: 20,
                  child: VerticalDivider(
                    color: Colors.redAccent,
                    width: 1,
                  ),
                ),
              ),
              _createButtonText(context),
              const Padding(
                padding: EdgeInsets.all(20),
                child: SizedBox(
                  height: 20,
                  child: VerticalDivider(
                    color: Colors.redAccent,
                    width: 1,
                  ),
                ),
              ),
            ],
          ))),
      // This trailing comma makes auto-formatting nicer for build methods.
    );
  }

  Widget _createButtonText(BuildContext context) {
    return FilledButton(
        style: ButtonStyle(
            backgroundColor: MaterialStateColor.resolveWith((states) {
          if (states.contains(MaterialState.pressed)) {
            return Colors.blue;
          } else if (states.contains(MaterialState.hovered)) {
            return Colors.redAccent;
          } else {
            return Colors.grey;
          }
        }),
            //     foregroundColor: MaterialStateColor.resolveWith((states) {
            //   if (states.contains(MaterialState.pressed)) {
            //     return Colors.blue;
            //   } else if (states.contains(MaterialState.hovered)) {
            //     return Colors.deepPurple;
            //   } else {
            //     return Colors.cyan;
            //   }
            // }),
            textStyle: MaterialStateTextStyle.resolveWith((states) {
          if (states.contains(MaterialState.pressed)) {
            return TextStyle(color: Colors.deepPurple);
          } else if (states.contains(MaterialState.hovered)) {
            return TextStyle(color: Colors.white);
          } else {
            return TextStyle(color: Colors.black);
          }
        })),
        child: const Text(
          "Save SP",
        ),
        onPressed: () {});
  }

  Widget _createButtonText2(BuildContext context) {
    return FilledButton(
        style: ButtonStyle(
            backgroundColor: MaterialStateColor.resolveWith((states) {
          if (states.contains(MaterialState.pressed)) {
            return Colors.blue;
          } else if (states.contains(MaterialState.hovered)) {
            return Colors.redAccent;
          } else {
            return Colors.grey;
          }
        }),
            //     foregroundColor: MaterialStateColor.resolveWith((states) {
            //   if (states.contains(MaterialState.pressed)) {
            //     return Colors.blue;
            //   } else if (states.contains(MaterialState.hovered)) {
            //     return Colors.deepPurple;
            //   } else {
            //     return Colors.cyan;
            //   }
            // }),
            textStyle: MaterialStateTextStyle.resolveWith((states) {
          if (states.contains(MaterialState.pressed)) {
            return TextStyle(color: Colors.deepPurple);
          } else if (states.contains(MaterialState.hovered)) {
            return TextStyle(color: Colors.white);
          } else {
            return TextStyle(color: Colors.black);
          }
        })),
        child: const Text(
          "Read SP",
        ),
        onPressed: () {});
  }
}
